package com.xmwzw.catpu.viewmodel;

import android.databinding.BaseObservable;
import android.databinding.Bindable;
import android.text.TextUtils;

import com.xmwzw.catpu.BaseApplication;
import com.xmwzw.catpu.util.Constant;
import com.xmwzw.catpu.util.SPFaceUtils;
import com.xmwzw.catpu.validator.PhoneValidator;
import com.xmwzw.catpu.validator.RangeValidator;

/**
 * @author : wangzw
 * @date : 20-4-1下午7:32
 * @desc :
 */
public class PwdChangeViewModel extends BaseObservable {
    private PhoneValidator phoneValidator = new PhoneValidator("");
    private RangeValidator passwordValidator = new RangeValidator("", 6, 20);

    @Bindable
    public String mAccount = "";

    @Bindable
    public String mOldPaw = "";

    @Bindable
    public String mNewPaw = "";

    @Bindable
    public String getValidateError() {

        String error = "";
        if (TextUtils.isEmpty(mAccount) || !phoneValidator.isValid(mAccount)) {
            error = "请填写有效的手机号";
        } else if (TextUtils.isEmpty(mOldPaw) || !passwordValidator.isValid(mOldPaw)) {
            error = "请填写有效的旧密码";
        } else if (!mOldPaw.equals(SPFaceUtils.get(BaseApplication.getInstance(), Constant.KEY_LOGIN_PAW,""))){
            error ="旧密码错误";
        }else if (mOldPaw.equals(mNewPaw)) {
            error = "新密码不能和旧密码一致";
        } else if (TextUtils.isEmpty(mNewPaw) || !passwordValidator.isValid(mNewPaw)) {
            error = "请填写有效的新密码";
        }
        return error;
    }
}